package de.hfu.mdsd.mm.guimodel.validation;

import org.eclipse.xtext.validation.Check;

import de.hfu.mdsd.mm.guimodel.guimodel.Array;
import de.hfu.mdsd.mm.guimodel.guimodel.Component;
import de.hfu.mdsd.mm.guimodel.guimodel.TwoDimensionalArray;
import de.hfu.mdsd.mm.guimodel.guimodel.View;

public class GuimodelJavaValidator extends AbstractGuimodelJavaValidator {

	@Check
	public void checkGreetingStartsWithCapital(Component component) {
		if (component.getName().length() <= 2) {
			error("Name for a component should have a minimum of 2 chars!",
					null);
		}
	}

	@Check
	public void checkViewStartsWithCapital(View view) {
		if (!Character.isUpperCase(view.getName().charAt(0))) {
			warning("Name should start with a capital!", null);
		}
	}

	@Check
	public void checkTable(TwoDimensionalArray array) {
		int columns = array.getColumnNames().getElements().size();
		for (Array a : array.getRows()) {
			if (columns > a.getElements().size()) {
				error("A Row need additional values", null);
			}
			if (columns < a.getElements().size()) {
				error("Current row has two many values", null);
			}
		}
	}
}
